package com.cevent.community.app.common.utils;/**
 * Created by Cevent on 2021/9/14.
 */

import com.cevent.community.app.common.exception.ValidatorException;
import org.springframework.util.StringUtils;

/**
 * @author cevent
 * @description 异常工具类
 * @date 2021/9/14 16:42
 */
public class ValidatorUtil {
    //1.非空校验
    public static void requiredEmpty(String str,String fieldName){
        if(StringUtils.isEmpty(str)){
            throw new ValidatorException(fieldName+" 不能为空!");
        }
    }
    //2.长度校验
    public static void requiredLength(String str,String fieldName,int min,int max){
        int length=0;
        if(!StringUtils.isEmpty(str)){
            length=str.length();
        }
        if(length<min || length>max){
            throw new ValidatorException(fieldName+"长度在："+min+"~"+max+"位!");
        }
    }
}
